package com.cn.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.gmall.common.result.Result;
import com.cn.gmall.model.product.BaseAttrInfo;
import com.cn.gmall.model.product.BaseSaleAttr;
import com.cn.gmall.model.product.SpuInfo;
import com.cn.gmall.model.product.SpuSaleAttr;
import com.cn.gmall.product.service.ManageService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.annotation.RequestScope;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuManageController {
    @Autowired
    ManageService manageService;


    /**
     * 根据spuId 查询销售属性集合
     * @param spuId
     * @return
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result<List<SpuSaleAttr>> getSpuSaleAttrList(@PathVariable("spuId") Long spuId) {
        List<SpuSaleAttr> list = manageService.getSpuSaleAttrList(spuId);
        return Result.ok(list);
    }






    /**
     * 保存spu
     * @param spuInfo
     * @return
     */

    @PostMapping("/saveSpuInfo")
    public  Result saveSpuInfo(@RequestBody SpuInfo spuInfo){

manageService.saveSpuInfo(spuInfo);

        return  Result.ok();
    }

    /**
     * 获取销售属性数据
     * @return
     */
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList() {
        List<BaseSaleAttr> list = manageService.getBaseSaleAttrList();
        return Result.ok(list);
    }

    /**
     * spu分页列表
     *
     * @param page
     * @param limit
     * @param spuInfo
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result selectSpuPage(@PathVariable Long page, @PathVariable Long limit, SpuInfo spuInfo) {
        Page<SpuInfo> spuInfoPage = new Page<>(page, limit);

        IPage<SpuInfo> spuPage = manageService.selectSpuPage(spuInfoPage, spuInfo);

        return Result.ok(spuPage);
    }


}
